package com.supcalls;

import cn.hutool.core.util.StrUtil;
import java.util.List;

public class StrUtilDemo {
    public static void main(String[] args) {
        // 1. isBlank() 判断字符串是否为空或全是空白字符
        String str1 = " ";
        System.out.println("isBlank(' " + str1 + " '): " + StrUtil.isBlank(str1));  // true

        // 2. isNotBlank() 判断字符串是否非空并且不全是空白字符
        String str2 = "hello";
        System.out.println("isNotBlank(' " + str2 + " '): " + StrUtil.isNotBlank(str2));  // true

        // 3. split() 按分隔符拆分字符串，返回 List<String>
        String str3 = "a,b,c";
        List<String> resultList = StrUtil.split(str3, ',');
        System.out.println("split('a,b,c', ','): ");
        for (String s : resultList) {
            System.out.println(s);
        }

        // 如果需要 String[]，可以转换 List 为数组
        String[] resultArray = resultList.toArray(new String[0]);
        System.out.println("Converted to String[]: ");
        for (String s : resultArray) {
            System.out.println(s);
        }

        // 4. join() 将多个字符串连接成一个
        String joined = StrUtil.join(",", "apple", "banana", "cherry");
        System.out.println("join(',', 'apple', 'banana', 'cherry'): " + joined);  // apple,banana,cherry

        // 5. replace() 替换字符串中的指定部分
        String str4 = "hello world";
        String replaced = StrUtil.replace(str4, "world", "hutool");
        System.out.println("replace('hello world', 'world', 'hutool'): " + replaced);  // hello hutool

        // 6. subPre() 获取字符串的前部分
        String str5 = "abcdef";
        System.out.println("subPre('abcdef', 3): " + StrUtil.subPre(str5, 3));  // abc

        // 7. emptyToNull() 空字符串转换为 null
        String str6 = "";
        System.out.println("emptyToNull(''): " + StrUtil.emptyToNull(str6));  // null

        // 8. capitalize() 将首字母大写
        String str7 = "hello";
        System.out.println("capitalize('hello'): " + StrUtil.upperFirst(str7));  // Hello
    }
}
